package com.kurumi.util;

import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PageIndexCheckUtils {

	public static Map<String,String> checkHQMS1(Map<String, Object> basicInfo){
		String errorCode = "error1";
		String errorItem = "年龄与出生日期的校验";
		Map<String,String> result =new HashMap<String, String>();
		Object birthdayObj = basicInfo.get("birthday");
		
		Object inHospitalDateTimeObj = basicInfo.get("inHospitalDateTime");
		//年龄（年）
		Object yearOfAgeObj = (Object) basicInfo.get("yearOfAge");
		//年龄（月）
		Object monthOfAgeObj = (Object) basicInfo.get("monthOfAge");
		//年龄（天）
		Object dayOfAgeObj = (Object) basicInfo.get("dayOfAge");
		
		if(birthdayObj!= null){
			if(yearOfAgeObj ==null && monthOfAgeObj == null && dayOfAgeObj == null){
				
				
				String errorDesc = "基本信息>年龄（年）不能为空！";
				result.put("errorCode", errorCode);
				result.put("errorItem", errorItem);
				result.put("errorDesc", errorDesc);
				return result;
			}else{
				String errorDesc = "年龄等于入院日期减出生日期（误差范围1岁）";
				Date birthday = null;
				try {
					birthday = DateUtil.dateParse((String)birthdayObj);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				Date inHospitalDateTime = null;
				try {
					inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)inHospitalDateTimeObj);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(inHospitalDateTime != null && birthday != null){
					Map<String, Integer> dateDiff = DateUtil.getYearMonthDay(birthday, inHospitalDateTime);
					if(dateDiff.get("year") != null && yearOfAgeObj != null){
						int age = dateDiff.get("year");
						if(!(age+1>=(int)yearOfAgeObj && (int)yearOfAgeObj>=age-1)){
							result.put("errorCode", errorCode);
							result.put("errorItem", errorItem);
							result.put("errorDesc", errorDesc);
							return result;
						}
					}
				}
				
			}
		}
		return null;
	}
	
	public static Map<String,String> checkHQMS2(Map<String, Object> basicInfo,Map<String, Object> operateInfo){
		Map<String,String> result =new HashMap<String, String>();
		if(operateInfo == null){
			return null;
		}
		String errorCode = "error2";
		String errorItem = "入院日期、入院后确诊日期、出院日期、手术操作日期关系校验";
		Object inHospitalDateTimeObj = basicInfo.get("inHospitalDateTime");
		Object outHospitalDateTimeObj = basicInfo.get("outHospitalDateTime");
		Object diagConfirmedDateTimeObj = basicInfo.get("diagConfirmedDateTime");
		
		Date inHospitalDateTime = null;
		Date outHospitalDateTime = null;
		Date diagConfirmedDateTime = null;
		try {
			inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)inHospitalDateTimeObj);
			outHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)outHospitalDateTimeObj);
			if(diagConfirmedDateTimeObj != null){
				diagConfirmedDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)diagConfirmedDateTimeObj);
			}
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		if(inHospitalDateTime != null && outHospitalDateTime != null){
			if(inHospitalDateTime.getTime() >outHospitalDateTime.getTime()){
				String errorDesc = "入院日期≤出院日期；";
				result.put("errorCode", errorCode);
				result.put("errorItem", errorItem);
				result.put("errorDesc", errorDesc);
				return result;
			}
			if(diagConfirmedDateTime != null){
				if(inHospitalDateTime.getTime() > diagConfirmedDateTime.getTime() ||
						diagConfirmedDateTime.getTime() > outHospitalDateTime.getTime()){
					String errorDesc = "入院日期≤入院后确诊日期≤出院日期；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					return result;
				}
			}
			
			if(operateInfo == null){
				return null;
			}
			List<Map<String, Object>> operateRecords = (List<Map<String, Object>>)operateInfo.get("operateRecords");
			for (Map<String, Object> operateRecord : operateRecords) {
				Object operateStartDateObj = operateRecord.get("operateStartDate");
				Date operateStartDate = null;
				try {
					operateStartDate = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)operateStartDateObj);
					
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(inHospitalDateTime.getTime() > operateStartDate.getTime() ||
						operateStartDate.getTime() > outHospitalDateTime.getTime()){
					String errorDesc = "入院日期≤手术操作日期≤出院日期；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					return result;
				}
			}
		}
		
		return null;
	}
	
	public static Map<String,String> checkHQMS3(Map<String, Object> basicInfo,Map<String, Object> cureInfo,Map<String, Object> diseaseDiagInfo){
		Map<String,String> result =new HashMap<String, String>();
		String errorCode = "error3";
		String errorItem = "抢救次数与抢救成功次数校验";
		String outHospitalTypeCode = (String)basicInfo.get("outHospitalTypeCode");
		Object rescueNumberObj = cureInfo.get("rescueNumber");
		Object rescueSucceedNumberObj = cureInfo.get("rescueSucceedNumber");
		if(rescueNumberObj != null || rescueSucceedNumberObj != null){
			int rescueNumber = 0;
			if(rescueNumberObj != null){
				rescueNumber = (int)rescueNumberObj;
			}
			int rescueSucceedNumber = 0;
			if(rescueSucceedNumberObj != null){
				rescueSucceedNumber = (int)rescueSucceedNumberObj;
			}
			if(rescueNumber != rescueSucceedNumber){
				if("4".equals(outHospitalTypeCode)
					|| "5".equals(outHospitalTypeCode)
					|| "9".equals(outHospitalTypeCode)){
					if(rescueNumber != rescueSucceedNumber + 1){
						String errorDesc = "抢救次数应等于抢救成功次数，离院方式出现4非医嘱离院、5死亡、9其他，抢救次数可以等于抢救成功次数加1，表示最后一次抢救未成功；";
						result.put("errorCode", errorCode);
						result.put("errorItem", errorItem);
						result.put("errorDesc", errorDesc);
						return result;
					}
				}else{
					if(diseaseDiagInfo == null){
						return null;
					}
					Map<String, Object> mainDiagRecord = (Map<String, Object>)diseaseDiagInfo.get("mainDiagRecord");
					boolean isRight = false;
					Object mainTreatResultCodeObj = mainDiagRecord.get("treatResultCode");
					if(mainTreatResultCodeObj != null){
						String mainTreatResultCode = (String)mainTreatResultCodeObj;
						if("3".equals(mainTreatResultCode)
							|| "4".equals(mainTreatResultCode)
							|| "9".equals(mainTreatResultCode)){
							isRight = true;
						}
					}
					
					List<Map<String, Object>> ohterDiseaseDiagRecords = (List<Map<String, Object>>)diseaseDiagInfo.get("diseaseDiagRecords");
					for (Map<String, Object> ohterDiseaseDiagRecord : ohterDiseaseDiagRecords) {
						Object otherTreatResultCodeObj = ohterDiseaseDiagRecord.get("treatResultCode");
						if(otherTreatResultCodeObj != null){
							String otherTreatResultCode = (String)otherTreatResultCodeObj;
							if("3".equals(otherTreatResultCode)
								|| "4".equals(otherTreatResultCode)
								|| "9".equals(otherTreatResultCode)){
								isRight = true;
							}
						}
					}
					
					if(isRight){
						String errorDesc = "抢救次数应等于抢救成功次数，主要诊断出院情况、其他诊断出院情况出现“3 未愈、4死亡、9其他”，抢救次数可以等于抢救成功次数加1，表示最后一次抢救未成功；";
						result.put("errorCode", errorCode);
						result.put("errorItem", errorItem);
						result.put("errorDesc", errorDesc);
						return result;
					}
						
				}
				
			}
			
		}
		
		
		return null;
	}
	
	public static Map<String,String> checkHQMS3_1(Map<String, Object> basicInfo,Map<String, Object> cureInfo,Map<String, Object> diseaseDiagInfo){
		Map<String,String> result =new HashMap<String, String>();
		String errorCode = "error3_1";
		String errorItem = "新生儿出生体重校验";
		Object dayOfAgeObj = (Object) basicInfo.get("dayOfAge");
		String babyBirthWeight = ObjectUtils.getStringValue(cureInfo.get("babyBirthWeight"));
		Object birthdayObj = basicInfo.get("birthday");
		
		Object inHospitalDateTimeObj = basicInfo.get("inHospitalDateTime");
		if(diseaseDiagInfo!= null){
			List<Map<String, Object>> ohterDiseaseDiagRecords = (List<Map<String, Object>>)diseaseDiagInfo.get("diseaseDiagRecords");
			boolean isBaby = false;
			for (Map<String, Object> ohterDiseaseDiagRecord : ohterDiseaseDiagRecords) {
				
				String otherDiagCode = ObjectUtils.getStringValue(ohterDiseaseDiagRecord.get("diseaseDiagCode"));
				if(otherDiagCode==null){
					otherDiagCode = ObjectUtils.getStringValue(ohterDiseaseDiagRecord.get("diseaseDiagOriginalCode"));
				}
				if(otherDiagCode!= null){
					if(otherDiagCode.startsWith("Z37")){
						isBaby = true;
						break;
					}
				}
			}
			if(isBaby){
				if(babyBirthWeight == null){
					String errorDesc = "当其他诊断为Z37或（年龄不足一周岁）年龄<=28天，或入院日期减出生日期<=20天，新生儿出生体重不能为空";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					return result;
				}
			}
		}
		
		
		return null;
	}
	
	public static Map<String,String> checkHQMS4(Map<String, Object> basicInfo,Map<String, Object> cureInfo){
		Map<String,String> result =new HashMap<String, String>();
		String errorCode = "error4";
		String errorItem = "新生儿入院体重完整性校验";
		//年龄（天）
		Object dayOfAgeObj = (Object) basicInfo.get("dayOfAge");
		Object babyInHospitalWeight = cureInfo.get("babyInHospitalWeight");
		Object birthdayObj = basicInfo.get("birthday");
		
		Object inHospitalDateTimeObj = basicInfo.get("inHospitalDateTime");
		
		if(dayOfAgeObj != null){
			int dayOfAge = (int)dayOfAgeObj;
			if(dayOfAge <=28 && babyInHospitalWeight == null){
				String errorDesc = "年龄不足1周岁的）年龄≤28天，新生儿入院体重不能为空；";
				result.put("errorCode", errorCode);
				result.put("errorItem", errorItem);
				result.put("errorDesc", errorDesc);
			}
		}else{
			if(birthdayObj != null && inHospitalDateTimeObj != null){
				Date birthday = null;
				try {
					birthday = DateUtil.dateParse((String)birthdayObj);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				Date inHospitalDateTime = null;
				try {
					inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)inHospitalDateTimeObj);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(birthday != null && inHospitalDateTime != null){
					Map<String, Integer> dateDiff = DateUtil.getYearMonthDay(birthday, inHospitalDateTime);
					if(dateDiff.get("day") != null){
						int day = dateDiff.get("day");
						if(day<=28 && babyInHospitalWeight == null){
						
							String errorDesc = "入院日期减出生日期≤28天时，新生儿入院体重不能为空；";
							result.put("errorCode", errorCode);
							result.put("errorItem", errorItem);
							result.put("errorDesc", errorDesc);
							return result;
						}
					}
				}
			}
		}
		return null;
	}
	
	public static Map<String,String> checkHQMS5(Map<String, Object> basicInfo){
		String errorCode = "error5";
		String errorItem = "（年龄不足1周岁的）年龄完整性校验";
		Map<String,String> result =new HashMap<String, String>();
		Object yearOfAge = basicInfo.get("yearOfAge");
		if(yearOfAge ==null){
			Object monthOfAge = basicInfo.get("monthOfAge");
			Object dayOfAge = basicInfo.get("dayOfAge");
			if(monthOfAge == null && dayOfAge == null){
				String errorDesc = "年龄小于1周岁即年龄为0时，（年龄不足1周岁的）年龄不能为空；";
				result.put("errorCode", errorCode);
				result.put("errorItem", errorItem);
				result.put("errorDesc", errorDesc);
			}
		}
		
		return null;
	}
	
	public static Map<String,String> checkHQMS6(Map<String, Object> basicInfo,Map<String, Object> intensiveCareInfo){
		if(intensiveCareInfo == null){
			return null;
		}
		String errorCode = "error6";
		String errorItem = "监护室进入时间、监护室退出时间关系校验";
		Map<String,String> result =new HashMap<String, String>();
		Object inHospitalDateTimeObj = basicInfo.get("inHospitalDateTime");
		Object outHospitalDateTimeObj = basicInfo.get("outHospitalDateTime");
		
		Date inHospitalDateTime = null;
		Date outHospitalDateTime = null;
		try {
			inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)inHospitalDateTimeObj);
			outHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)outHospitalDateTimeObj);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(intensiveCareInfo == null){
			return null;
		}
		List<Map<String, Object>> intensiveCareRecords = (List<Map<String, Object>>)intensiveCareInfo.get("intensiveCareRecords");
		
		for (Map<String, Object> intensiveCareRecord : intensiveCareRecords) {
			Object inIcuDateTimeObj = intensiveCareRecord.get("inIcuDateTime");
			Object outIcuDateTimeObj = intensiveCareRecord.get("outIcuDateTime");
			if(inIcuDateTimeObj!= null && outIcuDateTimeObj != null){
				Date inIcuDateTime = null;
				Date outIcuDateTime = null;
				try {
					inIcuDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)inIcuDateTimeObj);
					outIcuDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)outIcuDateTimeObj);
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				if(inHospitalDateTime.after(inIcuDateTime) 
					|| inIcuDateTime.after(outIcuDateTime)
					|| outIcuDateTime.after(outHospitalDateTime)){
					String errorDesc = "入院日期≤监护室进入时间≤监护室退出时间≤出院日期；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					return result;
				}
			}
		}
		return null;
	}
	
	
	public static List<Map<String,String>> checkHQMS7(Map<String, Object> costInfo){
		
		List<Map<String,String>> results =new ArrayList<Map<String,String>>();
		Object totalCostObj = costInfo.get("totalCost");
		Object selfCostObj = costInfo.get("selfCost");
		
		List<Map<String, Object>> costRecords = (List<Map<String, Object>>)costInfo.get("costRecords");
		Object p752Cost = null;Object p754Cost = null;
		Object p755Cost = null;Object p756Cost = null;
		Object p757Cost = null;Object p758Cost = null;
		Object p759Cost = null;Object p760Cost = null;
		Object p761Cost = null;Object p762Cost = null;Object p763Cost = null;
		Object p764Cost = null;Object p765Cost = null;
		Object p767Cost = null;Object p768Cost = null;
		Object p769Cost = null;Object p770Cost = null;Object p771Cost = null;
		Object p772Cost = null;Object p773Cost = null;
		Object p774Cost = null;Object p775Cost = null;
		Object p776Cost = null;Object p777Cost = null;
		Object p778Cost = null;Object p779Cost = null;
		Object p780Cost = null;Object p781Cost = null;
		for (Map<String, Object> costRecord : costRecords) {
			Object medicalCostTypeCode = costRecord.get("medicalCostTypeCode");
			Object costMoney = costRecord.get("costMoney");
			if(("C01001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p752Cost = costMoney;
			}else if(("C01002").equalsIgnoreCase((String)medicalCostTypeCode)){
				p754Cost = costMoney;
			}else if(("C01003").equalsIgnoreCase((String)medicalCostTypeCode)){
				p755Cost = costMoney;
			}else if(("C01999").equalsIgnoreCase((String)medicalCostTypeCode)){
				p756Cost = costMoney;
			}else if(("C02001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p757Cost = costMoney;
			}else if(("C02002").equalsIgnoreCase((String)medicalCostTypeCode)){
				p758Cost = costMoney;
			}else if(("C02003").equalsIgnoreCase((String)medicalCostTypeCode)){
				p759Cost = costMoney;
			}else if(("C02004").equalsIgnoreCase((String)medicalCostTypeCode)){
				p760Cost = costMoney;
			}else if(("C03001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p761Cost = costMoney;
			}else if(("C03002").equalsIgnoreCase((String)medicalCostTypeCode)){
				p762Cost= costMoney;
			}else if(("C03003").equalsIgnoreCase((String)medicalCostTypeCode)){
				p763Cost = costMoney;
			}else if(("C03004").equalsIgnoreCase((String)medicalCostTypeCode)){
				p764Cost = costMoney;
			}else if(("C03005").equalsIgnoreCase((String)medicalCostTypeCode)){
				p765Cost = costMoney;
			}else if(("C04001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p767Cost = costMoney;
			}else if(("C05001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p768Cost = costMoney;
			}else if(("C06001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p769Cost = costMoney;
			}else if(("C06002").equalsIgnoreCase((String)medicalCostTypeCode)){
				p770Cost = costMoney;
			}else if(("C07001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p771Cost = costMoney;
			}else if(("C07002").equalsIgnoreCase((String)medicalCostTypeCode)){
				p772Cost = costMoney;
			}else if(("C08001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p773Cost = costMoney;
			}else if(("C08002").equalsIgnoreCase((String)medicalCostTypeCode)){
				p774Cost = costMoney;
			}else if(("C08003").equalsIgnoreCase((String)medicalCostTypeCode)){
				p775Cost = costMoney;
			}else if(("C08004").equalsIgnoreCase((String)medicalCostTypeCode)){
				p776Cost = costMoney;
			}else if(("C08005").equalsIgnoreCase((String)medicalCostTypeCode)){
				p777Cost = costMoney;
			}else if(("C09001").equalsIgnoreCase((String)medicalCostTypeCode)){
				p778Cost = costMoney;
			}else if(("C09002").equalsIgnoreCase((String)medicalCostTypeCode)){
				p779Cost = costMoney;
			}else if(("C09003").equalsIgnoreCase((String)medicalCostTypeCode)){
				p780Cost = costMoney;
			}else if(("C99999").equalsIgnoreCase((String)medicalCostTypeCode)){
				p781Cost = costMoney;
			}
			
			
		}
		BigDecimal totalMoney = BigDecimal.ZERO;
		if(p752Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p752Cost));
		}
		if(p754Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p754Cost));
		}
		if(p755Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p755Cost));
		}
		if(p756Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p756Cost));
		}
		if(p757Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p757Cost));
		}
		if(p758Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p758Cost));
		}
		if(p759Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p759Cost));
		}
		if(p760Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p760Cost));
		}
		if(p761Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p761Cost));
		}
		if(p763Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p763Cost));
		}
		if(p767Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p767Cost));
		}
		if(p768Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p768Cost));
		}
		if(p769Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p769Cost));
		}
		if(p771Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p771Cost));
		}
		if(p772Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p772Cost));
		}
		if(p773Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p773Cost));
		}
		if(p774Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p774Cost));
		}
		if(p775Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p775Cost));
		}
		if(p776Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p776Cost));
		}
		if(p777Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p777Cost));
		}
		if(p778Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p778Cost));
		}
		if(p779Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p779Cost));
		}
		if(p780Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p780Cost));
		}
		if(p781Cost != null){
			totalMoney = totalMoney.add(getBigDecimalValue(p781Cost));
		}
		BigDecimal maxErrorMoney = new BigDecimal("1.2");
		BigDecimal minErrorMoney = new BigDecimal("-1.2");
		BigDecimal totalCost = BigDecimal.ZERO;
		if(totalCostObj != null){
			totalCost = getBigDecimalValue(totalCostObj);
		}
		BigDecimal diffMoney = totalCost.subtract(totalMoney);
		if(diffMoney.compareTo(minErrorMoney) < 0 || diffMoney.compareTo(maxErrorMoney) > 0){
			Map<String,String> result = new HashMap<String, String>();
			String errorCode = "error7";
			String errorItem = "住院总费用与分项费用之和关系校验";
			String errorDesc = "住院总费用（"+totalCost+"）应等于各分项费用（"+totalMoney+"）（除自付金额,临床物理治疗费,麻醉费,手术费,抗菌药物费用外）之和；（允许误差1.2）";
			result.put("errorCode", errorCode);
			result.put("errorItem", errorItem);
			result.put("errorDesc", errorDesc);
			results.add(result);
		}
		
		BigDecimal selfCost = BigDecimal.ZERO;
		if(selfCostObj != null){
			selfCost = getBigDecimalValue(selfCostObj);
		}
		diffMoney = totalCost.subtract(selfCost);
		if(diffMoney.compareTo(minErrorMoney) < 0 || totalCost.compareTo(BigDecimal.ZERO) < 0){
			Map<String,String> result = new HashMap<String, String>();
			String errorCode = "error8";
			String errorItem = "住院总费用与住院总费用其中自付金额关系校验";
			String errorDesc = "住院总费用（"+totalCost+"）必须大于等于住院总费用其中自付金额("+selfCost+")；（允许误差1.2）";
			result.put("errorCode", errorCode);
			result.put("errorItem", errorItem);
			result.put("errorDesc", errorDesc);
			results.add(result);
		}
		if(p761Cost != null){
			if(p762Cost != null){
				BigDecimal p761Money = getBigDecimalValue(p761Cost);
				BigDecimal p762Money = getBigDecimalValue(p762Cost);
				diffMoney = p761Money.subtract(p762Money);
				
				if(diffMoney.compareTo(minErrorMoney) < 0){
					Map<String,String> result = new HashMap<String, String>();
					String errorCode = "error9";
					String errorItem = "非手术治疗项目费、临床物理治疗费关系校验";
					String errorDesc = "非手术治疗项目费（"+p761Money+"）必须大于等于临床物理治疗费（"+p762Money+"）；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					results.add(result);
				}
			}
		}else{
			if(p762Cost != null){
				BigDecimal p762Money = getBigDecimalValue(p762Cost);
				if(p762Money.compareTo(maxErrorMoney) >0){
					Map<String,String> result = new HashMap<String, String>();
					String errorCode = "error9";
					String errorItem = "非手术治疗项目费、临床物理治疗费关系校验";
					String errorDesc = "非手术治疗项目费必须大于等于临床物理治疗费；（"+p762Cost+"）";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					results.add(result);
				}
			}
		}
		BigDecimal hqms10Cost = BigDecimal.ZERO;
		if(p764Cost != null){
			hqms10Cost = hqms10Cost.add(getBigDecimalValue(p764Cost));
		}
		if(p765Cost != null){
			hqms10Cost = hqms10Cost.add(getBigDecimalValue(p765Cost));
		}
		
		BigDecimal p763Money = BigDecimal.ZERO;
		if(p763Cost != null){
			p763Money = getBigDecimalValue(p763Cost);
		}
		
		diffMoney = p763Money.subtract(hqms10Cost);
		if(diffMoney.compareTo(minErrorMoney) < 0){
			Map<String,String> result = new HashMap<String, String>();
			String errorCode = "error10";
			String errorItem = "手术治疗费、麻醉费、手术费关系校验";
			String errorDesc = "手术治疗费（"+p763Money+"）必须大于等于麻醉费与手术费之和（"+hqms10Cost+"）；（允许误差1.2）";
			result.put("errorCode", errorCode);
			result.put("errorItem", errorItem);
			result.put("errorDesc", errorDesc);
			results.add(result);
		}
		
		if(p769Cost != null){
			if(p770Cost != null){
				BigDecimal p769Money = getBigDecimalValue(p769Cost);
				BigDecimal p770Money = getBigDecimalValue(p770Cost);
				diffMoney = p769Money.subtract(p770Money);
				if(diffMoney.compareTo(minErrorMoney) < 0){
					Map<String,String> result = new HashMap<String, String>();
					String errorCode = "error11";
					String errorItem = "西药费与抗菌药物费用关系校验";
					String errorDesc = "西药费（"+p769Money+"）必须大于等于抗菌药物费用（"+p770Money+"）；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					results.add(result);
				}
			}
		}else{
			if(p770Cost != null){
				BigDecimal p770Money = getBigDecimalValue(p770Cost);
				if(p770Money.compareTo(maxErrorMoney) >0){
					Map<String,String> result = new HashMap<String, String>();
					String errorCode = "error11";
					String errorItem = "西药费与抗菌药物费用关系校验";
					String errorDesc = "西药费必须大于等于抗菌药物费用（"+p770Cost+"）；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					results.add(result);
				}
			}
		}
		
		return results;
	}
	
	
	public static Map<String,String> checkHQMS12(Map<String, Object> basicInfo,Map<String, Object> cureInfo){
		String errorCode = "error12";
		String errorItem = "质控日期范围校验";
		Map<String,String> result =new HashMap<String, String>();
		Object inHospitalDateTimeObj = basicInfo.get("inHospitalDateTime");
		Object qualityControlDateTimeObj = cureInfo.get("qualityControlDateTime");
		Date inHospitalDateTime = null;
		Date qualityControlDateTime = null;
		try {
			if(inHospitalDateTimeObj != null){
				inHospitalDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)inHospitalDateTimeObj);
			}
			if(qualityControlDateTimeObj != null){
				qualityControlDateTime = DateUtil.dateParse(DateUtil.DATE_TIME_FORMATE,(String)qualityControlDateTimeObj);
			}
			
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(inHospitalDateTime != null && qualityControlDateTime != null){
			if(inHospitalDateTime.after(qualityControlDateTime)){

				String errorDesc = "质控日期不能早于入院日期；";
				result.put("errorCode", errorCode);
				result.put("errorItem", errorItem);
				result.put("errorDesc", errorDesc);
				return result;
			}
		}
		
		return null;
	}
	
	
	public static Map<String,String> checkHQMS13(Map<String, Object> basicInfo,Map<String, Object> cureInfo,Map<String, Object> diseaseDiagInfo){
		String errorCode = "error13";
		String errorItem = "生存矛盾校验";
		Map<String,String> result =new HashMap<String, String>();
		Object autopsyCode = basicInfo.get("autopsyCode");
		String outHospitalTypeCode = (String)basicInfo.get("outHospitalTypeCode");
		if(autopsyCode != null){
			if("1".equals((String)autopsyCode)){
				if("1".equals(outHospitalTypeCode)
						|| "2".equals(outHospitalTypeCode)
						|| "3".equals(outHospitalTypeCode)
						|| "4".equals(outHospitalTypeCode)
						|| "9".equals(outHospitalTypeCode)){
					
					String errorDesc = "死亡患者尸检1=是,则离院方式不能为“1 医嘱离院”，“2 医嘱转院”，“3 医嘱转社区卫生服务机构/乡镇卫生院”，“4 非医嘱离院”，“9 其他”；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					return result;
				}
			}
		}
		
		Object malignantTumorHighestDiagBasisCode = cureInfo.get("malignantTumorHighestDiagBasisCode");
		if(malignantTumorHighestDiagBasisCode != null){
			if("8".equals((String)malignantTumorHighestDiagBasisCode)){
				if("1".equals(outHospitalTypeCode)
						|| "2".equals(outHospitalTypeCode)
						|| "3".equals(outHospitalTypeCode)
						|| "4".equals(outHospitalTypeCode)
						|| "9".equals(outHospitalTypeCode)){
					String errorDesc = "最高诊断依据8=尸检,则离院方式不能为“1 医嘱离院”，“2 医嘱转院”，“3 医嘱转社区卫生服务机构/乡镇卫生院”，“4 非医嘱离院”，“9 其他”；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					return result;
				}
			}
		}
		Map<String, Object> mainDiagRecord = (Map<String, Object>)diseaseDiagInfo.get("mainDiagRecord");
		Object mainTreatResultCodeObj = mainDiagRecord.get("treatResultCode");
		if(mainTreatResultCodeObj != null){
			String mainTreatResultCode = (String)mainTreatResultCodeObj;
			if("4".equals(mainTreatResultCode)){
				if("1".equals(outHospitalTypeCode)
						|| "2".equals(outHospitalTypeCode)
						|| "3".equals(outHospitalTypeCode)
						|| "4".equals(outHospitalTypeCode)
						|| "9".equals(outHospitalTypeCode)){
					String errorDesc = "当主要诊断出院情况为“4 死亡”,则离院方式不能为“1 医嘱离院”，“2 医嘱转院”，“3 医嘱转社区卫生服务机构/乡镇卫生院”，“4 非医嘱离院”，“9 其他”；";
					result.put("errorCode", errorCode);
					result.put("errorItem", errorItem);
					result.put("errorDesc", errorDesc);
					return result;
				}
			}
		}
		
		List<Map<String, Object>> ohterDiseaseDiagRecords = (List<Map<String, Object>>)diseaseDiagInfo.get("diseaseDiagRecords");
		for (Map<String, Object> ohterDiseaseDiagRecord : ohterDiseaseDiagRecords) {
			Object otherTreatResultCodeObj = ohterDiseaseDiagRecord.get("treatResultCode");
			if(otherTreatResultCodeObj != null){
				String otherTreatResultCode = (String)otherTreatResultCodeObj;
				if("4".equals(otherTreatResultCode)){
					if("1".equals(outHospitalTypeCode)
							|| "2".equals(outHospitalTypeCode)
							|| "3".equals(outHospitalTypeCode)
							|| "4".equals(outHospitalTypeCode)
							|| "9".equals(outHospitalTypeCode)){
						String errorDesc = "当其他诊断出院情况为“4 死亡”,则离院方式不能为“1 医嘱离院”，“2 医嘱转院”，“3 医嘱转社区卫生服务机构/乡镇卫生院”，“4 非医嘱离院”，“9 其他”；";
						result.put("errorCode", errorCode);
						result.put("errorItem", errorItem);
						result.put("errorDesc", errorDesc);
						return result;
					}
				}
			}
		}
		
		return null;
	}
	
	
	private static BigDecimal getBigDecimalValue(Object obj){
		if(obj == null){
			return null;
		}
		if(obj instanceof BigDecimal){
			return ((BigDecimal)obj).setScale(2,BigDecimal.ROUND_HALF_UP);
		}else if(obj instanceof Double){
			return new BigDecimal((Double)obj).setScale(2,BigDecimal.ROUND_HALF_UP);
		}
		else if(obj instanceof Integer){
			return new BigDecimal((Integer)obj).setScale(2,BigDecimal.ROUND_HALF_UP);
		}
		else if(obj instanceof String){
			return new BigDecimal((String)obj).setScale(2,BigDecimal.ROUND_HALF_UP);
		}
		else{
			return null;
		}
	}
}
